module Toolable
  extend ActiveSupport::Concern

  included do
    def error!(msg)
      render json: { status: 500, data: { message: msg } }
    end

    def data!(data = nil)
      render json: { status: 200, data: { message: "ok", object: data } }
    end

    def rabbitmq_send(msg)
      queue = $rabbitmq_channel.queue("task_queue")
      queue.publish(ms)
    end

    
    def redis_exists(key)
      $redis_connection.exists(key)
    end

    def redis_get(key)
      $redis_connection.get(key)
    end

    def redis_keys
      $redis_connection.keys
    end

    def redis_set(key, value, *hash)
      $redis_connection.set(key, value, *hash)
    end

    def redis_ttl(key)
      $redis_connection.ttl(key)
    end

    def redis_expire(key, seconds)
      $redis_connection.expire(key, seconds)
    end

    def redis_del(key)
      $redis_connection.del(key)
    end
  end
end